<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>



        <c:if test="${not empty sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal}">
            Estas conectado como: ${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}
            <br/>            
            <a  href="/logout" >Desconectar</a>
            <br/>
            <a  href="/userSecured/mis_mensajes?usuario=${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}" >Ver mis mensajes</a>

        </c:if>
        <c:if test="${empty sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal}">
            <a  class="login" href="#login">Conectar</a>
            <div id="fancyLogin" style="display: none;">
                <div id="login">
                    <form id="formConectar">
                        <table>
                            <tr>
                                <td>Usuario:</td><td><input id="username" type="text" size="10"/></td>
                            </tr>
                            <tr>
                                <td>Contraseña:</td>
                                <td><input id="password" type="text" size="10"/></td>
                            </tr>
                            <tr>
                                <td colspan="2" align="right">
                                    <input type="button" value="Conectar" id="botonConectar"/>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </c:if>


            <script type="text/javascript">

            $(document).ready(


            function(){



                $("a.login").fancybox(
                {
                    'modal'                     : true,
                    'showCloseButton'           : false,
                    'enableEscapeButton'     	: true,
                    'transitionIn'	:	'fade',
                    'transitionOut'	:	'fade',
                    'speedIn'		:	1200,
                    'speedOut'		:	1200,
                    'overlayShow'	:	true,
                    'autoDimensions'    :       true
                });



                $("#botonConectar").click(
                function (event) {
                    $.fancybox.close();
                    $.getJSON(
                    "/login",
                    {
                        "username": $("#username").val(),
                        "password": $("#password").val()
                    },
                    function(str) {
                        if (str) {
                            alert(str);
                        }
                        enlaceConectar();
                    }
                );
                }
            );
            }
        );
        </script>